#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "crypto/types.h"
#include "crypto/errors.h"
#include "crypto/base64.h"

int printSafeArray(SAFE_array *sa)
{
    if (sa == NULL)
    {
        export(CODE_PARAMS_ERROR, "Param is NULL!");
    }
    for (int i = 0; i < sa->size; i++)
    {
        printf("%c", sa->data[i]);
    }
    return CODE_SUCCESS;
}

int main()
{
    while (1)
    {
        char data[1024];
        scanf("%s", data);
        int cap = sizeof(data) + 1;
        SAFE_array *a = (SAFE_array *)malloc(offset(SAFE_array, data) + cap);
        a->cap = cap;
        a->size = strlen(data);
        strcpy(a->data, data);

        SAFE_array *b = NULL;
        encodeBase64(a, &b);
        printf("\ndata:\t%s\n", data);
        printf("encode:\t");
        printSafeArray(b);
        printf("\n");

        SAFE_array *c = NULL;
        decodeBase64(b, &c);
        printf("\ndata:\t");
        printSafeArray(b);
        printf("\n");
        printf("decode:\t");
        printSafeArray(c);
        printf("\n");
    }
    return 0;
}